﻿namespace Vibstudio.X4NET
{
    public class ConversionResult : OperationResult
    {
        protected ConversionResult(string additionalInfo, bool isPerfomed, string message)
            : base(isPerfomed, message)
        {
            AdditionalInfo = additionalInfo;
        }

        public string AdditionalInfo { get; set; }

        public static ConversionResult CreateSuccess(string additionalInfo)
        {
            return new ConversionResult(additionalInfo, true, "");
        }

        public static ConversionResult CreateFailure(string additionalInfo, string message)
        {
            return new ConversionResult(additionalInfo, false, message);
        }
    }

    public class ConversionResult<TInput, TOutput> : ConversionResult where TOutput : new()
    {
        protected ConversionResult(string additionalInfo, bool isPerfomed, string message, TInput input, TOutput output)
            : base(additionalInfo, isPerfomed, message)
        {
            Input = input;
            Output = output;
        }

        protected ConversionResult(string additionalInfo, bool isPerfomed, string message)
            : base(additionalInfo, isPerfomed, message)
        {
        }

        public TInput Input { get; set; }

        public TOutput Output { get; set; }

        public static ConversionResult<TInput, TOutput> CreateSuccess(TInput input, TOutput output, string additionalInfo = "")
        {
            return new ConversionResult<TInput, TOutput>(additionalInfo, true, "", input, output);
        }

        public static ConversionResult<TInput, TOutput> CreateFailure(TInput input, string message)
        {
            return new ConversionResult<TInput, TOutput>("", false, message, input, default(TOutput));
        }
    }
}